/*
 * Java学习论坛
 * Copyright 2017 (C) All Rights Reserved.
 */
package cn.studyjava.verify.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.studyjava.verify.mybatis.entity.App;
import cn.studyjava.verify.mybatis.entity.AppExample;
import cn.studyjava.verify.mybatis.entity.Auth;
import cn.studyjava.verify.mybatis.entity.AuthExample;
import cn.studyjava.verify.mybatis.mapper.AppMapper;
import cn.studyjava.verify.mybatis.mapper.AuthMapper;
import cn.studyjava.verify.service.IAuthService;


/**
 * <p>
 * Description:
 * </p>
 * 
 * @author: zsljava
 * @version 1.0.0
 * <p>
 * History:
 * -----------------------------------------------
 * @Date: 2017年8月8日 下午2:24:04
 * @author: zsljava
 * @version 1.0.0
 * @OP: Create
 * -----------------------------------------------
 * </p>
 *
 * @since
 * @see
 */
@Service
public class AuthServiceImpl implements IAuthService {

	@Autowired
	private AppMapper appMapper;
	
	@Autowired
	private AuthMapper authMapper;
	
	/**
	 * @Title: getAppKeyByAppId
	 * @Description:
	 * @param appId
	 * @return
	 * @see cn.studyjava.verify.service.IAuthService#getAppKeyByAppId(java.lang.String)
	 */
	@Override
	public String getAppKeyByAppId(String appId) {
		AppExample example = new AppExample();
		example.createCriteria().andAppIdEqualTo(appId);
		List<App> auths = appMapper.selectByExample(example);
		if(!auths.isEmpty()){
			return auths.get(0).getAppKey();
		}
		return null;
	}

	/**
	 * @Title: verify
	 * @Description: TODO
	 * @param authId
	 * @param appId
	 * @see cn.studyjava.verify.service.IAuthService#verify(java.lang.String, java.lang.String)
	 */
	@Override
	public Auth verify(String authId, String appId) {
		AuthExample example = new AuthExample();
		example.createCriteria().andAppIdEqualTo(appId).andAuthIdEqualTo(authId);
		List<Auth> auths = authMapper.selectByExample(example);		
		if(!auths.isEmpty()){
			return auths.get(0);
		}
		return null;
	}

	@Override
	public int addAuth(Auth auth) {
		return authMapper.insertSelective(auth);
	}

}
